(function ($) {
    $.getUrlParam = function (name) {
        var url = location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            var strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return theRequest[name];
    }
})(jQuery);

(function ($) {
    $.loadUser = function (user) {
            var usr = $.getUrlParam(user);
            console.log("url.user="+usr);
            if (typeof(usr) != "undefined" && usr != null && usr.length > 0) {
                return usr;
            }

            usr = getCookie(user);
            console.log("cookie.user="+usr);
            if (typeof(usr) != "undefined" && usr != null && usr.length > 0) {
                return usr;
            }

            while (typeof(usr) != "undefined" && usr == null || usr.length == 0){
                usr = prompt("请输入您的姓名：");
                console.log("prompt.user="+usr);
            }
            setCookie(user, usr);
            return usr;
    }
})(jQuery);

(function ($) {
    $.loadFile = function (file) {
            var f = $.getUrlParam(file);
            console.log("url.file="+f);
            while (typeof(f) == "undefined" || f == null || f.length == 0){
                f = prompt("请输入文件名：");
                console.log("prompt.file="+f);
            }
            return f;
    }
})(jQuery);


function getCookie(name)
{
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if(arr=document.cookie.match(reg))
        return unescape(arr[2]);
    else
        return null;
}
function setCookie(name,value)
{
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function delCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null)
        document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}